// Shader: 纹理与颜色叠加
const renderEngine = cc.renderer.renderEngine;
const renderer = renderEngine.renderer;

var shader = {
    name: "geoOverlay",
    params:[
        {name: 'iOverlayColor', type: renderer.PARAM_FLOAT4, defaultValue: {x:1.0, y:1.0, z:1.0, w:1.0}},
    ],
    defines:[],
    start(sprite, material) {
    },

    vert: `uniform mat4 viewProj;
        attribute vec3 a_position;
        attribute vec2 a_uv0;
        varying vec2 uv0;
        void main () {
            vec4 pos = viewProj * vec4(a_position, 1);
            gl_Position = pos;
            uv0 = a_uv0;
        }
        `,

    frag: `uniform sampler2D texture;
        varying vec2 uv0;
        uniform vec4 color;
        uniform vec4 iOverlayColor;
        void main() 
        {
            vec4 texColor = texture2D(texture, uv0) * color;
            gl_FragColor = vec4(iOverlayColor.rgb * iOverlayColor.a + texColor.rgb * (1.0 - iOverlayColor.a), texColor.a);
        }`,
}

let CustomMaterial = require('CustomMaterial');
CustomMaterial.addShader(shader);